package com.aysafety.eventmodel.config;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

@Configuration public class ScheduleConfigure implements SchedulingConfigurer {
    private Logger logger = LoggerFactory.getLogger(ScheduleConfigure.class);
    @Autowired private ScheduleThreadPoolConfig config;

    @Override public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {

        ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(config.getCorePoolSize(),
            new BasicThreadFactory.Builder().namingPattern("corn-schedule-pool-%d").daemon(true).build());


        scheduledTaskRegistrar.setScheduler(executorService);
    }
}
